﻿myApp.controller('PropertyMarketingDetailController', function ($scope, $http, $routeParams,$filter,NgMap,$location, $rootScope) {
  
    $scope.isSearch = true;
    $scope.isAndroid = $rootScope.isAndroid;


    //$scope.share = {};
    var BASE_URL;
    if ($location.host() == "localhost") {
        BASE_URL = $location.protocol() + "://" + "localhost:" + $location.port();
    } else {
        BASE_URL = $location.protocol() + "://" + $location.host();
    }

    $scope.current_path_url = $location.absUrl();




    pageInit();
    function pageInit(){ 
        var url = 'api/PropertyDirectory/GetPropertyDirectory/' + $routeParams.id;
        $http.get(url).success(function (data) {
            console.log("MARKETING DETAIL PAGE: " + JSON.stringify(data));
            $scope.slides = data.pictureList;

            $scope.Project = data.project;

            if (!$scope.slides) {
                $scope.slides = [];
                $scope.slides.push({ pictureURL: 'http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png' });
            }


            $scope.modify = function (object) {
                return object.replace(new RegExp('\r?\n', 'g'), '<br />')
            }

            $scope.shareTitle = data.project.ProjectName;
            $scope.shareDescription = data.project.ProjectDetails;
            $scope.shareURL = BASE_URL + "/property/marketing/details/" + data.project.ProjectId;
            $scope.shareImageURL = data.project.PropertyURL || "http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png";

            $scope.googleShareURL = encodeURI(encodeURI($scope.shareURL));

            $scope.isSearch = false;
        }).error(function (err) {
            alert("There is a problem loading detail. Please try again later.");
            $scope.isSearch = false;
        });
          
    }

    $scope.submitForm = function (obj) {
        var url = 'https://script.google.com/macros/s/AKfycbwcomu5o2CIbkO1lCjyZhDrF_dejSPWi0VAj9knYKYRr3jHDUY/exec';
        $http({
            method: 'POST',
            url: url,
            data: $(obj.target).serialize(),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (data) {
            alert("Thanks for Subscribing to our Newsletter!");
            $scope.subscription_email = "";
        });
    }




});